import java.awt.DisplayMode;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;


public class BuckyAnimationMain {
	private Screen screen;
	private Image bg;
	private Animation a;
	
	public static void main(String args[]){
		DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
		BuckyAnimationMain b = new BuckyAnimationMain();
		b.run(dm);
	}
	
	//main engine to run
	public void run(DisplayMode dm){
		screen = new Screen();
		try{
			screen.setFullScreen(dm, new JFrame());
			loadPics();
			movieLoop();
		}finally{
			screen.restoreScreen();
		}
	}
	
	public void loadPics(){
		bg = new ImageIcon("D:\\Developer\\workspace\\JavaGame\\img\\mabinogi_2005_07_26_001.jpg").getImage();
		Image face1 = new ImageIcon("D:\\Developer\\workspace\\JavaGame\\img\\hahaha.jpg").getImage();
		Image face2 = new ImageIcon("D:\\Developer\\workspace\\JavaGame\\img\\hahaha2.jpg").getImage();
		a = new Animation();
		a.addScene(face1, 250);
		a.addScene(face2, 250);
	}
	
	public void movieLoop(){
		long startingTime = System.currentTimeMillis();
		long	cumTime = startingTime;
		
		while(cumTime - startingTime < 5000){
			long timePassed = System.currentTimeMillis() - cumTime;
			cumTime += timePassed;
			a.update(timePassed);
			Graphics g = screen.getFullScreenWindow().getGraphics();
			draw(g);
			g.dispose();
			try{
				Thread.sleep(20);
			}catch(Exception e){
				
			}
		}
	}
	
	//draw method
	public void draw(Graphics g){
		g.drawImage(bg, 0, 0, null);
		g.drawImage(a.getImage(), 0, 0, null);
	}
	
}